package grafica;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.PrintWriter;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import net.Client;

public class ChatPanel extends JPanel implements ActionListener {
	
	JTextArea text = new JTextArea(6,30);
	JTextField input = new JTextField("",30);
	JButton invia = new JButton("invia");
	JPanel sotto = new JPanel();
	JScrollPane scroll = new JScrollPane(text);
	PrintWriter out;
	
	
	public ChatPanel(PrintWriter out) {
		text.setEditable(false);
		this.out = out;
		invia.addActionListener(this);
		this.setFocusable(false);
		this.setLayout(new BorderLayout());
		this.add(scroll,BorderLayout.CENTER);
		sotto.setLayout(new BorderLayout());
		sotto.add(input,BorderLayout.CENTER);
		sotto.add(invia,BorderLayout.EAST);
		this.add(sotto,BorderLayout.SOUTH);
		
	}	


	public void setOut(PrintWriter out) {
		this.out = out;
	}


	public void actionPerformed(ActionEvent e) {
		String in = input.getText();
		out.println("*"+in);
		input.setText("");		
	}

	public JTextArea getText() {
		return text;
	}

}
